home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 June / SGI Freeware 1998 June.iso / dist / fw_UMINNgopher.idb / usr / freeware / src / gopher_1.12 / gopherd / NeXTindex.c.z / NeXTindex.c
C/C++ Source or Header  |  1997-09-09  |  4KB  |  143 lines

  1. /********************************************************************
  2.  * $Author: drich $
  3.  * $Revision: 1.1 $
  4.  * $Date: 1995/10/03 04:08:21 $
  5.  * $Source: /proj/freeware1.0/gopher1.12/src/gopherd/RCS/NeXTindex.c,v $
  6.  * $Status: $
  7.  *
  8.  * Paul Lindner, University of Minnesota CIS.
  9.  *
  10.  * Copyright 1991, 1992 by the Regents of the University of Minnesota
  11.  * see the file "Copyright" in the distribution for conditions of use.
  12.  *********************************************************************
  13.  * MODULE: NeXTindex.c
  14.  * index interface to the NeXT text indexing routines. 
  15.  *********************************************************************
  16.  * Revision History:
  17.  * $Log: NeXTindex.c,v $
  18.  * Revision 1.1  1995/10/03  04:08:21  drich
  19.  * gopher 1.2 check-in
  20.  *
  21.  * Revision 1.1  1992/12/10  23:13:27  lindner
  22.  * gopher 1.1 release
  23.  *
  24.  *
  25.  *********************************************************************/
  26.  
  27. #include <sys/stat.h>
  28. #include "text/wftable.h"
  29. #include "text/ix.h"
  30.  
  31. #include "gopherd.h"
  32.  
  33. int
  34. myInterruptRoutine()
  35. {
  36.      /* for now, always return 0 so the search is not interrupted */
  37.      return(0);
  38. }
  39.  
  40. void
  41. NeXTIndexQuery(sockfd, SearchWords, ZIndexDirectory, DatabaseNm, INDEXHost, INDEXPort, INDEXPath)
  42.   int sockfd;
  43.   char *SearchWords;
  44.   char *ZIndexDirectory;
  45.   char *DatabaseNm;  /*** Not used by the next indexer... ***/
  46.   char *INDEXHost;
  47.   int INDEXPort;
  48.   char *INDEXPath;
  49. {
  50.      unsigned long i;
  51.      char *cp;
  52.      int j;
  53.      Index *workingIndex;
  54.      RefList theRefList;
  55.      RefList *ptrtheRefList;
  56.      Reference *MyReference;
  57.      FileCell *f;
  58.      char tempstr[40];
  59.      char outputline[1024];
  60.      GopherObj *gs;
  61.      GopherDirObj *gd;
  62.  
  63.      gs = GSnew();
  64.      gd = GDnew(32);
  65.  
  66.      if (DEBUG) {
  67.       printf("Nextindexer called: Search %s, Indexdir %s\n", SearchWords, ZIndexDirectory);
  68.      }
  69.  
  70.      /*** Try to open the index a couple of times ***/
  71.      for (j=0; j< 4; j++) {
  72.       workingIndex = ixOpen( ZIndexDirectory, "r" );
  73.       if (workingIndex != NULL)
  74.            break;
  75.       else
  76.            usleep (50);
  77.      }
  78.  
  79.      if ( workingIndex != 0 ) {
  80.       theRefList = ixIndexQuery(workingIndex, SearchWords, ixSearchByFullWord,
  81.                     ixMatchContent, ixLiteralString,
  82.                     (myInterruptRoutine));
  83.  
  84.       for( i=0; i < theRefList.n; i++ ){
  85.            MyReference = &(theRefList.r[i]);
  86.            f = (*MyReference).f;
  87.            
  88.            /*** The Selector String ***/
  89.            /*** So far we only index text files, so put a 0 in front ***/
  90.  
  91.            if (strstr((*f).file, ".cache") != NULL) {
  92.             continue;
  93.            }
  94.            
  95.            GSsetType(gs, '0');
  96.            /*** Process the description field, remove any crud, replace
  97.                     with spaces. ***/
  98.                {
  99.             char *moo = f->desc;
  100.             while (*moo != '\0') {
  101.                 if (!isprint(*moo))
  102.                     *moo = ' ';
  103.                 moo++;
  104.             }
  105.         }
  106.         
  107.            GSsetTitle(gs, (f->desc)+1);
  108.            GSsetHost(gs, INDEXHost);
  109.            GSsetPort(gs, INDEXPort);
  110.  
  111.            cp = strstr(f->file, INDEXPath);
  112.            if (cp == NULL)
  113.             sprintf(outputline, "0/%s", f->file);
  114.            else
  115.             sprintf(outputline, "0/%s", cp);
  116.  
  117.            if (MacIndex)
  118.             GSsetPath(gs, f->file);
  119.            else
  120.                    GSsetPath(gs, outputline);
  121.            GSsetWeight(gs, (int)(MyReference->weight * 1000.0));
  122.            GDaddGS(gd, gs);
  123.       }
  124.  
  125.       if (UsingHTML)
  126.            GDtoNetHTML(gd, sockfd);
  127.       else
  128.            GDtoNet(gd, sockfd);
  129.  
  130.       writestring(sockfd, ".\r\n");
  131.       
  132.      }
  133.      else {
  134.       fprintf(stderr,"can't open working index\n" );
  135.      }
  136.  
  137.      GSdestroy(gs);
  138.      GDdestroy(gd);
  139.      
  140.      /* all done.... close the index file */
  141. }
  142.  
  143.